#!/usr/bin/env perl
###############################################################################
#
# Wrapper application that randomize a sequence
# Developed by Rafael Garabato [rafael.garabato@fudepan.org.ar]
#
###############################################################################
#
# FuDePAN
# Copyright (C) 2009 Rafael Garabato, FuDePAN
#
#   randomize.pl is part of sequtils.
#
#   sequtils is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   sequtils is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with sequtils.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

use strict;
use warnings;
require 5;



# Needed Modules
use lib './modules';
use Getopt::Long;
use BioUtils::SeqUtils;


my $callerScriptName;
my $sequence;
my $helpMode;

#Grabbing out the caller script name 
$callerScriptName = $0;

#Parsing out the provided arguments
#Check that enough arguments were provided
if ( @ARGV > 0 )
{
	#Display help if one of the needed arguments are missing
	GetOptions(
	    'sequence=s'     => \$sequence,
	    'help|?' => \$helpMode,
	    ) or usage($callerScriptName, "Invalid Arguments were provided");
}
else
{
	usage($callerScriptName, "No arguments were provided");
}


#Help menu was called
if( defined ($helpMode) or not defined($sequence) )
{
	usage($callerScriptName); 
}
elsif (defined($sequence) )
{
	my $randomsequence = BioUtils::SeqUtils::randomizeSequence($sequence); 
	print "$randomsequence\n";
}



#################################################################################################
# Functions

#######
# Print usage information
# Parameter: script name
# Returns: nothing
#
sub usage 
{
    my ($caller, $stringToDisplay) = @_;

	if ( defined ($stringToDisplay) )
	{
		print("Problem detected: $stringToDisplay\n");	
	} 

	#printing help
	die << "EOF";
Secuence randomizer script
Developed by Rafael Garabato [rafael.garabato at fudepan.org.ar]
Usage: $caller [options] (please use quotes for "long inputs")
Required options:   --sequence	Sequence to randomize
                                        
Optional options: --help            Help Menu
EOF
}




